import { ModalProps } from "@/components/MModal/index.vue";

/**
 * @description modal 对话框操作方法封装
 * */
export interface ModalMethod {
  openDialog: (content: string, api?: Function, params?: any, db?: Function) => void;
}

export const useModal = () => {
  const modalParams = reactive<ModalProps>({
    visible: false,
    content: "",
    api: () => null,
    params: {},
    callbackMethod: () => null
  });

  const openDialog = (content: string, api?: Function, params?: any, db?: Function): void => {
    Object.assign(modalParams, {
      visible: true,
      api,
      params,
      content,
      callbackMethod: db
    });
  };

  return {
    modalParams,
    openDialog
  };
};
